<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        .main{
            width: 300px;
            margin: 0 auto;
        }
        #btn{
            width: 100%;
            height: 30px;
        }
        img{
            display: block;
        }
        #imgBox{
            width: 100%;
        }
    </style>
</head>
<body>
    <div class="main" id="main">
        <button id="btn">隐藏</button>
        <img id="imgBox" src="../images/1.webp" alt="">
    </div>
</body>
</html>
<script>
    var obtn=document.getElementById("btn");
    var oimg=document.getElementById("imgBox");

    obtn.onclick=function(){
        var value=obtn.innerHTML;
        if(value=="隐藏"){
            obtn.innerText="显示";
            oimg.style.display="none";
        }else{
            obtn.innerText="隐藏";
            oimg.style.display="block";
        }
    }
</script>